﻿#region Copyright 2008 - Evolution Systems.
//
// Author: José Rogério Ferreira dos Santos(joserogerio.santos@gmail.com)
// Date: 19/04/2009
// Time: 8:06
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: ${FILE_NAME}.cs
#endregion
using System;
using System.Drawing;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;

namespace csharp.rad.finan.entries
{
	/// <summary>
	/// Description of frmViewBillPlan.
	/// </summary>
	public partial class frmViewBillPlan : KryptonForm
	{
		public string billId;
		
		private Bills 		listBills	    = new Bills();
		//private SubClasss listSubClass	 = new SubClasss();
		//private Classs 	listClass		 = new Classs();
		private SubGroups listSubGroups	 = new SubGroups();
		private Groups    listGroups		 = new Groups();
		
		public frmViewBillPlan()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
		}
		
		private void FrmViewBillPlanLoad(object sender, EventArgs e)
		{
			listGroups.fillList();
			listSubGroups.fillList();
			//listClass.fillList();
			//listSubClass.fillList();
			listBills.fillList();
			
			setGroups();
		}
		
		private void setGroups()
		{
			int tam, i;
			
			tam = listGroups.count();
			for(i=0; i < tam; i++)
			{
				TreeNode aux = new TreeNode(listGroups.get(i).name);
				tvwMain.Nodes.Add(aux);
				setSubGroups(aux, listGroups.get(i).id);
			}
		}		
		
		private void setSubGroups(TreeNode node, string groupId)
		{
			int tam, i;
			listSubGroups.filterByGroup(groupId);
			
			tam = listSubGroups.count();
			
			for(i=0; i < tam; i++)
			{
				TreeNode aux = new TreeNode(listSubGroups.get(i).name);
				node.Nodes.Add(aux);
				//setClass(aux, listSubGroups.get(i).id);
				setBills(aux, listSubGroups.get(i).id);
			}
			listSubGroups.disableFilter();
		}
		
		/*
		private void setClass(TreeNode node, string subGroupId)
		{
			int tam, i;
			listClass.filterBySubGroup(subGroupId);
			
			tam = listClass.count();
			
			for(i=0; i < tam; i++)
			{
				TreeNode aux = new TreeNode(listClass.get(i).name);
				node.Nodes.Add(aux);
				setSubClass(aux, listClass.get(i).id);
			}
			listClass.disableFilter();
		}
		
		private void setSubClass(TreeNode node, string classId)
		{
			int tam, i;
			listSubClass.filterByClass(classId);
			
			tam = listSubClass.count();
			
			for(i=0; i < tam; i++)
			{
				TreeNode aux = new TreeNode(listSubClass.get(i).name);
				node.Nodes.Add(aux);
				setBills(aux, listSubClass.get(i).id);
			}
			listSubClass.disableFilter();
		}
		*/
		
		private void setBills(TreeNode node, string subGroupId)
		{
			int tam, i;
			listBills.filterSubGroup(subGroupId);
			
			tam = listBills.count();
			
			for(i=0; i < tam; i++)
			{
				TreeNode aux = new TreeNode(listBills.get(i).name);
				aux.Tag = "leaf";
				node.Nodes.Add(aux);
			}
			listBills.disableFilter();
		}		
		
		
		void BtnOKClick(object sender, EventArgs e)
		{
			if (tvwMain.SelectedNode.Tag.ToString().Equals("leaf"))
			{
				listBills.searchByName(tvwMain.SelectedNode.Text);
				
				billId = listBills.get().id;
			}
		}
	}
}
